#include "showvideo.h"
#include <QStringList>
#include <QDir>
#include <QDebug>
#include <QTimer>
#include "frame.h"

ShowVideo::ShowVideo(QWidget *parent) :
    QWidget(parent)
{
    QString strPath = Frame::strRoot +"/adm/MediaFile";
    QDir dir(strPath);
    dir.setFilter(QDir::Files);
    m_fileInfoList = dir.entryInfoList();

    onChangeVideo();

}

void ShowVideo::onChangeVideo()
{
    if(m_fileInfoList.size() == 0)
        return;
    QFileInfo fileInfo = m_fileInfoList.at(0);

    this->mplayerProcess = new QProcess(this);

    render = new QWidget(this);
    render->move(0,0);
    render->resize(543,355);

    QStringList args;
    args << "-slave";
    args << "-quiet";
    args << "-wid"<<QString::number(render->winId());
    //args << strPath + "MV.flv";
    args << fileInfo.filePath();

//    qDebug() << QDir::currentPath()+"/MV.flv";

    this->mplayerProcess->start("/usr/bin/mplayer", args);


    m_fileInfoList.removeFirst();
    m_fileInfoList.append(fileInfo);

}

ShowVideo::~ShowVideo()
{
    this->mplayerProcess->close();
}

/*
ShowPic::ShowPic(QWidget *parent) :
    QLabel(parent)
{
    QString strPath = Frame::strRoot +"/adm/PicFile";
    QDir dir(strPath);
    dir.setFilter(QDir::Files);
    m_fileInfoList = dir.entryInfoList();

    onChangePic();

    QTimer* timer = new QTimer();
    timer->start(1000);
    connect(timer, SIGNAL(timeout()), this, SLOT(onChangePic()));
}

void ShowPic::onChangePic()
{
    if(m_fileInfoList.size() == 0)
        return;
    QFileInfo fileInfo = m_fileInfoList.at(0);

    QPixmap map(fileInfo.filePath());
    setPixmap(map);

    m_fileInfoList.removeFirst();
    m_fileInfoList.append(fileInfo);
}
*/
